<!-- 试试index.vue如何识别 -->
<template>
  <div class='returnsManagement'>
    <!-- 顶部筛选条件 -->
    <div>
      <a-radio-group v-model="ListType"
                     size="large" @change="change">
        <a-radio-button value="">
          全部申请（{{listLength.allCount}}）
        </a-radio-button>
        <a-radio-button value="TO_AUDIT">
          待处理（{{listLength.toAudit}}）
        </a-radio-button>
        <a-radio-button value="REFUND_FINISH">
          已完成（{{listLength.refundFinishCount}}）
        </a-radio-button>
        <a-radio-button value="REVIEW_FAILED">
          已拒绝（{{listLength.reviewFatledCount}}）
        </a-radio-button>
      </a-radio-group>
    </div>
    <!-- 列表 -->
    <search-form-table :url="url"
                       ref="searchtable"
                       :hideSelect="true"
                       :columns="columns"
                       :form="form"
                       style="margin-top:20px;"
                       :ListType="ListType"  >

      <template slot="searchForm">
        <a-form layout="inline"
                :form="form">
          <a-form-item label="退款单号">
            <a-input v-decorator="['id']"
                     placeholder="请输入退款单号"> </a-input>
          </a-form-item>

          <a-form-item label="收货人">
            <a-input v-decorator="['userName']"
                     placeholder="收货人手机号/姓名"> </a-input>
          </a-form-item>

          <a-form-item label="申请时间">
            <fast-range-picker
              v-decorator="[
                'createStartDate-createEndDate',
              ]">
            </fast-range-picker>
          </a-form-item>


        </a-form>
      </template>

      <template slot="oprationRow">
        <permission authority="">
          <a-button @click="exportExcel()" style="margin-left: 90%;">导出</a-button>
        </permission>
        <!--  <permission authority="">
            <a-button style="" @click="deleteRows($refs.searchtable.selectedRowKeys)">删除</a-button>
          </permission>-->
      </template>

      <template slot="tableOperation"
                slot-scope="{ record }">

        <permission authority="">
          <span class="text-primary pointer"
                @click="openInfo(record)">查看详情</span>
        </permission>

      </template>

    </search-form-table>
  </div>
</template>

<script>
  import SearchFormTable from "./SearchTable/index";
  export default {
    name: '',
    components: {
      SearchFormTable
    },
    directives: {},
    filters: {},
    mixins: [],
    model: {},
    props: {},
    data() {
      return {
        ListType:'',
        // 各类数据长度
        listLength:{},
        url: '/order/goodsrepairs/refund/page',
        currentRecord: {},
        form: this.$form.createForm(this, { name: 'table_search' }),
        columns: [
          {
            title: '退款单号',
            dataIndex: 'id',
            key: 'id',
            align: 'center',
          },
          {
            title: '申请时间',
            dataIndex: 'createDate',
            key: 'createDate'
          },
          {
            title: '用户账号',
            dataIndex: 'userPhone',
            key: 'userPhone'
          },
          // {
          //   title:'归属展厅',
          //   dataIndex:'phone',
          //   key:'phone'
          // },
          {
            title: '退款金额',
            dataIndex: 'refundPrice',
            key: 'refundPrice',
            align: "center",
            customRender: (text, row) => {
              // console.log("text", text);
              return (text/100).toFixed(2)+'元'

            },
          },
          {
            title: '联系人',
            dataIndex: 'userName',
            key: 'userName'
          },
          {
            title: '申请状态',
            dataIndex: 'returnGoodsStatus',
            key: 'returnGoodsStatus',
            customRender: (text, row) => {
              // console.log("text", text);
              switch (text) {
                case 'TO_AUDIT':
                  return '待处理'
                case 'REFUND_OF':
                  return '退款中'
                case 'USER_CANCEL':
                  return '撤销申请'
                case 'REFUND_FINISH':
                  return '已完成'
                case 'REVIEW_FAILED':
                  return '已拒绝'
              }

            },
          },
          {
            title: '处理时间',
            dataIndex: 'updateDate',
            key: 'updateDate',
          },
          {
            title: '操作',
            dataIndex: 'operation',
            scopedSlots: { customRender: 'operation' }
          }
        ]
      }
    },
    computed: {},
    watch: {},
    beforeCreate() { },
    created() {
      this.getItemsLength()
    },
    beforeMount() { },
    mounted() {

    },
    // 方法集合
    methods: {
      change(){
        // 改变就重调接口找数据
        this.$refs.searchtable.handleSearch()
      },

      openInfo(record) {
        console.log('record:',record)
        this.currentRecord = record
        this.$router.push({
          name: 'OrderReturnsMoneyManagementInfo',
          query: {
            id: record.id,
            applyStatus:record.returnGoodsStatus
          }
        })
      },

      // 获取各类数据个数
      async getItemsLength(){
        const res = await this.$get(`/order/goodsrepairs/total?repairsType=1`)
        if (res && res.returnCode === 1000){
          this.listLength = res.dataInfo
        }
      },

      // 批量删除
      deleteRows (ids) {
        // ids   是单号数组
        console.log(ids)
        if (!ids || ids.length === 0) return this.$message.warn('请先选择一项后再进行操作')
        this.$confirm({
          title: '删除提示',
          content: '删除操作不可恢复，请确认是否删除？',
          okText: '确认删除',
          cancelText: '取消',
          onOk: () => {
            this.$post('', ids).then(res => {
              if (res && res.returnCode == 1000) {
                this.$message.success('删除成功')
                this.$refs.searchtable.handleSearch()
              }
            })
          }
        })
      },
      // 导出excel
      exportExcel () {
        const params = this.$refs.searchtable.searchParams || {}
        const selectedIds = this.$refs.searchtable.selectedRowKeys
        console.log(selectedIds )
        if (selectedIds && selectedIds.length) {
          params['id'] = selectedIds.join(',')
        }
        console.log(params)
        this.$export('/order/goodsrepairs/export',params)
        // this.$export('/order/goodsrepairs/export', params)
      }
    }
  }
</script>
<style rel='stylesheet/less' lang='less' scoped>
  //@import url();
</style>
